/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Nov 15, 2013  3:48:30 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.interfaces.construction.rise.high
 * File Name : ConstructionContractHighRiseController.java
 * TODO
 */
package com.tis.interfaces.construction.rise.high;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jpa.entitys.synchro.staging.AGenDesc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import promis.utility.CommonService;
import apps.ApplConfiguration;
import apps.business.process.construction.contract.ContractContractorHighRiseProcessing;

import com.tis.interfaces.commons.IServletCommon;
import com.tis.interfaces.commons.ServletCommon;
import com.tis.interfaces.commons.XmlResultback;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Nov 15, 2013 : 3:48:30 PM 
 * CreateBy=Chatree Siangklom
 * 
 * ConstructionContractHighRiseController
 * TODO
 */
@Controller
@RequestMapping(value=ConstructionContractHighRiseController.url)
public class ConstructionContractHighRiseController extends ServletCommon implements IServletCommon {
	private static final Logger logging = LoggerFactory.getLogger(ConstructionContractHighRiseController.class);
	public static final String url = "/servlet/construction/rise/high/contract";

	/** (Javadoc)
	 * @see com.tis.interfaces.commons.IServletCommon#index(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 * Date =Nov 15, 2013 : 3:48:30 PM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override 
	@RequestMapping(method = RequestMethod.GET)
	public HttpEntity<byte[]> index(HttpServletRequest request, HttpServletResponse response) throws Exception {
		logging.info("Welcome ConstructionContractHighRiseController --->index");
		XmlResultback xmlResultback = new XmlResultback(promis.utility.ProcessModule.CONSTRUCTION_CONTRACT_HIGH_RISE.toString(), null, new Date());
		
		try{
			
			Map mapValue = super.initParam(request);
	    	AGenDesc aGenDesc = new ApplConfiguration().GetInterfaceChannel(
																			CommonService.ConvertStringToBigDecimal("1001"), 
																			CommonService.ConvertStringToBigDecimal("1002"), 
																			promis.utility.BusinessModule.CONSTRUCTION_HIGH_RISE.toString(), 
																			promis.utility.ProcessModule.CONSTRUCTION_CONTRACT_HIGH_RISE.toString());
	    	if(CommonService.IsNullRString(aGenDesc.getValue3()).equals("Q")){
	    		new apps.promis.out.common.SyncQueueAction().PutQueue(	promis.utility.BusinessModule.CONSTRUCTION_HIGH_RISE.toString(), 
																		promis.utility.ProcessModule.CONSTRUCTION_CONTRACT_HIGH_RISE.toString(),
																		null,
																		processAction,
																	 	mapValue);
	    		
	    		xmlResultback.setMsgcode("QS");
	    		xmlResultback.setMsgDescription("Queue Success");
	    		
	    	}else if(CommonService.IsNullRString(aGenDesc.getValue3()).equals("D")){
	    		
	    		new ContractContractorHighRiseProcessing().ProcessingContarct1(company, project, documentNo, status, syncIsstaging);
	    		
	    		xmlResultback.setMsgcode("PS");
	    		xmlResultback.setMsgDescription("Processing Success");
	    	}
		}catch (Exception e) {
	    	xmlResultback.setMsgcode("EE");
			xmlResultback.setMsgDescription(e.getMessage());
	    	e.printStackTrace();
	    	logging.error("Error:" + e.getMessage());
		}
		return(ToXml(xmlResultback));
	}

}
